/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author WinKiQue58
 */
@Entity
@Table(name = "SERVICE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Service.findAll", query = "SELECT s FROM Service s"),
    @NamedQuery(name = "Service.findByIdService", query = "SELECT s FROM Service s WHERE s.servicePK.idService = :idService"),
    @NamedQuery(name = "Service.findByIdBranchenterprise", query = "SELECT s FROM Service s WHERE s.servicePK.idBranchenterprise = :idBranchenterprise"),
    @NamedQuery(name = "Service.findByIdEnterprise", query = "SELECT s FROM Service s WHERE s.servicePK.idEnterprise = :idEnterprise")})
public class Service implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ServicePK servicePK;
    @ManyToMany(mappedBy = "serviceList", fetch = FetchType.LAZY)
    private List<Product> productList;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "service", fetch = FetchType.LAZY)
    private ServicePreference servicePreference;
    @JoinColumns({
        @JoinColumn(name = "ID_BRANCHENTERPRISE", referencedColumnName = "ID_BRANCHENTERPRISE", insertable = false, updatable = false),
        @JoinColumn(name = "ID_ENTERPRISE", referencedColumnName = "ID_ENTERPRISE", insertable = false, updatable = false)})
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private BranchEnterprise branchEnterprise;

    public Service() {
    }

    public Service(ServicePK servicePK) {
        this.servicePK = servicePK;
    }

    public Service(BigInteger idService, BigInteger idBranchenterprise, BigInteger idEnterprise) {
        this.servicePK = new ServicePK(idService, idBranchenterprise, idEnterprise);
    }

    public ServicePK getServicePK() {
        return servicePK;
    }

    public void setServicePK(ServicePK servicePK) {
        this.servicePK = servicePK;
    }

    @XmlTransient
    public List<Product> getProductList() {
        return productList;
    }

    public void setProductList(List<Product> productList) {
        this.productList = productList;
    }

    public ServicePreference getServicePreference() {
        return servicePreference;
    }

    public void setServicePreference(ServicePreference servicePreference) {
        this.servicePreference = servicePreference;
    }

    public BranchEnterprise getBranchEnterprise() {
        return branchEnterprise;
    }

    public void setBranchEnterprise(BranchEnterprise branchEnterprise) {
        this.branchEnterprise = branchEnterprise;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (servicePK != null ? servicePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Service)) {
            return false;
        }
        Service other = (Service) object;
        if ((this.servicePK == null && other.servicePK != null) || (this.servicePK != null && !this.servicePK.equals(other.servicePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Service[ servicePK=" + servicePK + " ]";
    }
    
}
